extends layout

block meta
    link(rel="stylesheet", href="#{options.cdn_path}/js/artDialog/skins/combo?/js/artDialog/skins/default.css&v=#{options.site_version}")
    style
        .block-heading img {
            margin-right: 8px;
            border-radius: 10%;
            width: 30px;
        }

block content
    .navbar
        .navbar-inner
            a.brand(href="/")
                span.first #{options.site_name}
    .row-fluid
        .dialog
            .block
                p.block-heading
                    img(src="#{photourl}") 
                    |您好：#{nickname}，来自#{type}的朋友！
                .block-body
                    form(action="/admin/binding", method="post")
                        label=nouser?"请绑定您的邮箱帐号：":"请使用邮箱激活帐号："
                        input.span12(type="email", name="email", required="required", original-title="推荐使用网易或QQ邮箱，<br />部分邮箱可能收不到邮件！")
                        input(type="hidden", name="id", required="required", value=id)
                        input.btn.btn-primary.pull-right(type="submit", value="确认")
                        .clearfix

block script
    script(src="#{options.cdn_path}/js/artDialog/jquery.artDialog.min.js?v=#{options.site_version}")
    script
        $(function(){
            $('form').submit(function(){
                var email = $('input[name="email"]').val();
                if(/^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/.test(email)){
                    var dialog = $.dialog();
                    $.post($(this).attr("action")
                        , $('form').serialize()
                        , function (data){
                            if(data.status == 0){
                                dialog.content('邮箱发送成功，请进入邮箱按提示完成绑定！').lock().time(2000);
                                var email_url = '/';
                                if (email.indexOf('mail') > 0) {
                                    email_url = 'http://' + email.substr(email.indexOf('@') + 1, email.length);
                                } else {
                                    email_url = 'http://mail.' + email.substr(email.indexOf('@') + 1, email.length);
                                }
                                setTimeout(function(){
                                    location.href = email_url;
                                }, 2000);
                            }else if(data.status == 1) {
                                dialog.title('提示！');
                                dialog.content('邮件发送失败，请重试！').lock().time(2000);
                            }else {
                                dialog.content('请尝试重新登陆！').lock().time(1000);
                                setTimeout(function(){
                                    location.href = "/sign_in";
                                }, 1000);
                            }
                        }
                    );
                } else {
                    $.dialog({content: "邮箱格式不对！", time: 1000});
                }
                return false;
            });
        });